package com.ruoyi.system.api;

/**
 * Response返回结果
 *
 * @author yzg
 * @ClassName ResponseWithData.java
 * @date 2019-09-23 10:14
 */

public class ResponseWithData<T extends Object> {

    public final static int RESULT_SUCCESS = 0;

    public final static int RESULT_ERROR = 1;

    public final static int RESULT_SIGN_INVALID = 2;

    //TODO 后面修改为不同的值，和异地登录3区分开
    public final static int RESULT_TOKEN_INVALID = 3;

    //TODO 后面修改为不同的值，和异地登录3区分开
    public final static int RESULT_SERVER_ERROR = 3;

    //异地登录 状态码 3
    public final static int RESULT_REMOTE_LOGIN_INVALID = 3;

    private int code;
    private String msg;
    private T data;

    public ResponseWithData code(int code) {
        this.setCode(code);
        return this;
    }

    public ResponseWithData msg(String msg) {
        this.setMsg(msg);
        return this;
    }

    public ResponseWithData data(T data) {
        this.setData(data);
        return this;
    }

    public ResponseWithData success() {
        this.setCode(RESULT_SUCCESS);
        return this;
    }

    public ResponseWithData success(T data) {
        this.setCode(RESULT_SUCCESS);
        return data(data);
    }

    public ResponseWithData error() {
        this.setCode(RESULT_ERROR);
        return this;
    }

    public ResponseWithData error(String msg) {
        this.msg = msg;
        return this.error();
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
